package com.tj.bo.common.conf.api;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fqgj.common.api.Page;
import com.tj.bo.common.conf.enums.BasicErrorCodeEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: binary-option
 * @description
 * @author: binary
 * @create: 2020-06-10 18:26
 **/
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class ApiResponse<T> {

    private Integer code = BasicErrorCodeEnum.SUCCESS.getCode();

    private String msg = "SUCCESS";

    private T data;

    private Page page;

    public ApiResponse() {
    }

    public ApiResponse(T data) {
        this.data = data;
    }

    public ApiResponse(T data, Page page) {
        this.data = data;
        this.page = page;
    }

    public ApiResponse(String key, T data) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, data);
        this.data = (T) map;
    }

    public ApiResponse(Integer errorCode, String errorMsg) {
        this.code = errorCode;
        this.msg = errorMsg;
    }

    public Integer getCode() {
        return code;
    }

    public ApiResponse<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public ApiResponse<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public ApiResponse<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Page getPage() {
        return page;
    }

    public ApiResponse<T> setPage(Page page) {
        this.page = page;
        return this;
    }
}
